package _02array;

public class _02SearchUnsortArray {
    // search
    // time complexity: O(n)
    // space complexity: O(1)
    private static int findKey(int arr[], int n, int key) {
        for(int i = 0; i < n; ++i) {
            if(arr[i] == key)
                return i;
        }
        return -1;
    }

    public static void main(String[] args) {
        int arr[] = {10, 8, 30, 40, 20};
        int n = arr.length;

        // search 40
        int key = 40;
        int index = findKey(arr, n, key);

        System.out.println("index:" + index);

    }
}
